package com.gis3c.online.entry;

import com.gis3c.spatial.entity.BaseFeature;
import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by hukekuan on 2018/3/16.
 */
public class AirStation extends BaseFeature {
    private String stationId;
    private String stationName;
    private String stCode;
    private String areaCode;
    private String areaName;
    private Double longitude;
    private Double latitude;
    private Integer adminCode;
    private Integer aqi;
    private String level;
    private String levelStatus;
    private String mainPollute;
    private String itemCode;
    private String dateTime;

    public String getStationId() {
        return stationId;
    }

    public void setStationId(String stationId) {
        this.stationId = stationId;
    }

    public String getStCode() {
        return stCode;
    }

    public void setStCode(String stCode) {
        this.stCode = stCode;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Integer getAdminCode() {
        return adminCode;
    }

    public void setAdminCode(Integer adminCode) {
        this.adminCode = adminCode;
    }

    public Integer getAqi() {
        return aqi;
    }

    public void setAqi(Integer aqi) {
        if(aqi == null){
            this.aqi =  -1;
        }else {
            this.aqi = aqi;
        }

        Map<String,String> levelMap = getLevelFromAQI(aqi);
        this.level = levelMap.get("level");
        this.levelStatus = levelMap.get("status");
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getLevelStatus() {
        return levelStatus;
    }

    public void setLevelStatus(String levelStatus) {
        this.levelStatus = levelStatus;
    }

    public String getMainPollute() {
        return mainPollute;
    }

    public void setMainPollute(String mainPollute) {
        if(mainPollute == null || "".equals(mainPollute)){
            this.mainPollute ="--";
        }else {
            this.mainPollute = mainPollute;
        }
    }

    public String getDateTime() {
        return dateTime;
    }

    public void setDateTime(String dateTime) {
        this.dateTime = dateTime;
    }

    public String getStationName() {
        return stationName;
    }

    public void setStationName(String stationName) {
        this.stationName = stationName;
    }

    public String getItemCode() {
        return itemCode;
    }

    public void setItemCode(String itemCode) {
        if(itemCode == null || "".equals(itemCode)){
            this.itemCode ="--";
        }else {
            this.itemCode = itemCode;
        }
    }

    private Map<String,String> getLevelFromAQI(Integer aqi){
        Map<String,String> result = new HashMap<>();

        if(aqi == null || aqi == -1){
            result.put("level","--");
            result.put("status","--");
        }else {
            int aqlValue = aqi.intValue();
            if(aqlValue <= 50){
                result.put("level","Ⅰ");
                result.put("status","优");
            } else if(aqlValue > 50 && aqlValue <= 100){
                result.put("level","Ⅱ");
                result.put("status","良");
            }else if(aqlValue > 100 && aqlValue <= 150){
                result.put("level","Ⅲ");
                result.put("status","轻度污染");
            }else if(aqlValue > 150 && aqlValue <= 200){
                result.put("level","Ⅳ");
                result.put("status","中度污染");
            }else if(aqlValue > 200 && aqlValue <= 300){
                result.put("level","Ⅴ");
                result.put("status","重度污染");
            }else if(aqlValue > 300){
                result.put("level","Ⅵ");
                result.put("status","严重污染");
            }
        }
        return result;
    }
}
